package com.alex.seo.service.campaign.executor;

import org.springframework.beans.factory.annotation.Required;

import com.alex.seo.domain.campaign.Campaign;
import com.alex.seo.domain.campaign.PublishingCampaign;

public class CampaignExecutorLookupService {

	private CampaignExecutor<PublishingCampaign> publishingCampaignExecutor;
	
	@Required
	public void setPublishingCampaignExecutor(CampaignExecutor<PublishingCampaign> publishingCampaignExecutor) {
		this.publishingCampaignExecutor = publishingCampaignExecutor;
	}
	
	@SuppressWarnings("unchecked")
	public <CampaignType extends Campaign> CampaignExecutor<CampaignType> lookup(CampaignType campaign) {
		if (campaign instanceof PublishingCampaign) {
			return (CampaignExecutor<CampaignType>) publishingCampaignExecutor;
		} else {
			throw new IllegalArgumentException("Could not lookup campaign executor for campaign: " + campaign.getClass().getSimpleName());
		}
	}
	
}
